//
//  UserModel.m
//  SportSocial
//
//  Created by yull on 14/12/28.
//  Copyright (c) 2014年 yull. All rights reserved.
//

#import "UserModel.h"

@implementation UserModel

+ (instancetype)userWithDict:(NSDictionary *)dict
{
    UserModel *userModel = [[UserModel alloc] init];
    
    for (NSString *key in dict.allKeys) {
        id value = [dict objectForKey:key];
        if ([value isKindOfClass:[NSNull class]]) {
            value = @"";
        }
        
        [userModel setValue:value forKey:key];
    }
    
    return userModel;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    if ([key isEqualToString:@"id"]) {
        [self setValue:value forKeyPath:@"userId"];
    }
}

+ (instancetype)userWithResultSet:(FMResultSet *)resultSet
{
    UserModel *user = [[UserModel alloc] init];
    user.userId = [resultSet longLongIntForColumn:@"userId"];
    user.name = [resultSet stringForColumn:@"name"];
    user.sex = [resultSet intForColumn:@"sex"];
    user.icon = [resultSet stringForColumn:@"icon"];
    return user;
}
@end
